package com.service;

import com.convert.NewsConverter;
import com.dao.BaseDao;
import com.http.News;
import com.module.NoticeEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * version 1.0.0
 *
 * @author KKW
 * @date 2017/7/7.
 */
@Service("newsService")
public class NewsService extends BaseService{
    @Autowired
    BaseDao<NoticeEntity> newsdao;

    @Transactional(readOnly = true)
    public List<News> getAllNews(){
        String hql="from NoticeEntity";
        double sum=1;
        for(int i=0;i<0xffffff;i++){
            sum=sum*1.01+i;
            if(sum>0x1fffffff) sum=1;
        }
        return NewsConverter.convert(newsdao.search(hql));
    }

    /**
     * cacheable注解为方法添加缓存，每次执行方法前，若有缓存，则不执行方法
     * @return
     */
    @Cacheable(value = "newsCache")
    @Transactional(readOnly = true)
    public List<News> getAllNewsCache(){
        String hql="from NoticeEntity";
        double sum=1;
        for(int i=0;i<0xffffff;i++){
            sum=sum*1.01+i;
            if(sum>0x1fffffff) sum=1;
        }
        return NewsConverter.convert(newsdao.search(hql));
    }
}
